﻿using PMIS.Shared.Models;
using PMIS.WebApi.Model;
using SqlSugar;
using System.Linq.Expressions;

namespace PMIS.WebApi.Services
{
    public interface IBaseService<TEntity> where TEntity : class
    {
        
        #region 新增

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        Task<int> AddEntityAsync(TEntity entity);


        /// <summary>
        /// 批量添加实体
        /// </summary>
        /// <param name="entitys">实体集合</param>
        /// <returns></returns>
        Task<int> AddEntityListAsync(List<TEntity> entitys);

        #endregion

        #region 修改

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <param name="lstIgnoreColumns">忽略列</param>
        /// <param name="isLock">是否加锁</param>
        /// <returns></returns>
        Task<int> UpdateEntityAsync(TEntity entity, List<string> lstIgnoreColumns = null, bool isLock = true);

        /// <summary>
        /// 批量更新实体
        /// </summary>
        /// <param name="entitys">实体集合</param>
        /// <returns></returns>
        Task<int> UpdateEntityListAsync(List<TEntity> entitys);

        #endregion

        #region 删除

        /// <summary>
        /// 逻辑删除 操作的类需继承IDeletedFilter
        /// </summary>
        /// <param name="exp"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        Task<int> DeleteEntityAsync<T>(Expression<Func<T, bool>> exp) where T : class, IDeletedFilter, new();

        #endregion

        #region Queryable

        /// <summary>
        /// 泛型Queryable
        /// </summary>
        ISugarQueryable<TEntity> Table { get; }

        Task<TEntity> GetEntityAsync(string id);

        Task<PagingModel<TEntity>> GetEntityListAsync(int? pageNum, int? pageSize, Expression<Func<TEntity, bool>>? predicate = null);

        /// <summary>
        /// 泛型Queryable
        /// </summary>
        /// <param name="whereExpression">条件表达式</param>
        /// <param name="orderExpression">排序表达式</param>
        /// <param name="orderByType">排序方式</param>
        /// <returns></returns>
        ISugarQueryable<TEntity> QueryEntity(Expression<Func<TEntity, bool>> whereExpression = null,
            Expression<Func<TEntity, object>> orderExpression = null, OrderByType? orderByType = null);

        #endregion
    }
}
